package com.sky.controller.user;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@RestController("userShopController")
@RequestMapping("/user/shop")
@Api(tags = "店铺相关接口")
@Slf4j
public class ShopController {

    public final static String KEY = "SHOP_STATUS";

    @Autowired
    private RedisTemplate redisTemplate;

    /*
    * 查询店铺营业状态
    * */
     //注意区分，上面的设置店铺营业状态是{status}，表示的是路径参数
     //下面的查询店铺营业状态是@GetMapping("/status")，表示的字符串，表示的是查询参数
    @GetMapping("/status")
    @ApiOperation("查询店铺营业状态")
    public Result<Integer> getStatus(){
        Integer shopStatus = (Integer) redisTemplate.opsForValue().get("KEY");
        log.info("查询店铺营业状态：{}",shopStatus==1?"营业":"打烊");
        return Result.success(shopStatus);
    }
}
